//
//  SANavigationController.m
//  01_kakin
//
//  Created by jon due on 12/03/21.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "SANavigationController.h"

@implementation SANavigationController


-(void)SApushViewController:(UIViewController *)viewController animated:(SAAnimationType)type{
    
    NSString *animeType;
    
    if(type == SAAnimationTypeTop){
        animeType = kCATransitionFromTop;
        
    }else if(type == SAAnimationTypeLeft){
        animeType = kCATransitionFromLeft;
        
    }else if (type == SAAnimationTypeRight){
        animeType = kCATransitionFromRight;
        
    }else{
        animeType = kCATransitionFromBottom;
    }
    
    //View display Animation
    CATransition *animation = [CATransition animation];
    [animation setType:kCATransitionMoveIn];
    [animation setSubtype:animeType];
    [animation setDuration:0.5];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    
    [viewController.view.layer addAnimation:animation forKey:nil];
    
    [ self pushViewController:viewController animated:NO ];
}

- (UIViewController *)SApopViewControllerAnimated:(SAAnimationType)type{
    
    NSString *animeType;
    
    if(type == SAAnimationTypeTop){
        animeType = kCATransitionFromTop;
        
    }else if(type == SAAnimationTypeLeft){
        animeType = kCATransitionFromLeft;
        
    }else if (type == SAAnimationTypeRight){
        animeType = kCATransitionFromRight;
        
    }else{
        animeType = kCATransitionFromBottom;
    }
    
    //View display Animation
    CATransition *animation = [CATransition animation];
    [animation setType:kCATransitionMoveIn];
    [animation setSubtype:animeType];
    [animation setDuration:1.5];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    
    [self.topViewController.view.layer addAnimation:animation forKey:nil];

    return [ self popViewControllerAnimated:NO ];
}


@end
